<template>
  <el-dialog append-to-body
             :before-close="cancel"
             :visible.sync="value">
    <template slot="title">公司总输赢</template>
    <el-table border
              :data="tableData"
              show-summary
              :summary-method="getSummaries">
      <el-table-column label="游戏平台"
                       prop="gameName"></el-table-column>
      <!--新增版本-->
      <el-table-column label="平台做庄公司输赢"
                       prop="win">
                       <template slot-scope="{row}">{{row.win | currency}}</template>
                       </el-table-column>
      <el-table-column label="玩家对战公司抽水"
                       prop="waterFee">
                       <template slot-scope="{row}">{{row.waterFee | currency}}</template>
                       </el-table-column>
      <el-table-column label="公司总盈利"
                       prop="winTotal">
        <template slot-scope="{row}">{{row.winTotal | currency}}</template>
      </el-table-column>
      <!--结束-->
    </el-table>
    <div slot="footer"
         class="dialog-footer">
      <el-button type="primary"
                 @click="$emit('input',false)">确定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { gameCommission } from '@/services/api/commission';
import { grid } from '@/build';

export default {
  name: 'game-commission-dialog',
  props: ['value', 'id'],
  mixins: [grid],
  data() {
    return {
      tableData: [],
    };
  },
  methods: {
    cancel() {
      this.$emit('input', false);
    },
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        const values = data.map(item => Number(item[column.property]));
        if (index === 0) {
          sums[index] = '总计';
          return;
        }
        // if ([2].indexOf(index) !== -1) {
        //   sums[index] = '';
        //   return;
        // }
        sums[index] = values.reduce((prev, curr) => {
          const value = Number(curr);
          if (!isNaN(value)) {
            return (prev + curr);
          }
          return prev;
        }, 0);
      });
      const total = [];
      sums.map((item, i) => {
        if (i != 0) {
          item = _.currency(item);
          return total.push(item);
        }
        return total.push(item);
      });
      return total;
    },
  },
  computed: {},
  mounted() {
    this.bindGet(gameCommission, 'tableData', {
      sendingData: { detailId: this.id },
    });
    this.getAll();
  },
};
</script>

<style scoped>
</style>
